321846e9c1416ab29b7d37dcb7024f2ebd2a8562,community/kernel/src/test/java/org/neo4j/kernel/impl/store/MetaDataStoreTest.java,MetaDataStoreTest,transactionClosedMustBeAtomic,#,535

Before Change


            int lowerLimit = 100;
            long endTime = currentTimeMillis() + SECONDS.toMillis( 10 );

            BooleanSupplier end = () ->
            {
                boolean upperBoundReached = writeCount.get() >= upperLimit &&
                        fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit;
                boolean lowerBoundReached = writeCount.get() >= lowerLimit &&
                        fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit;
                return !upperBoundReached || (currentTimeMillis() >= endTime && lowerBoundReached);
            };
            Race race = new Race();
            race.addContestants( 3, until( end, () -> {
                long count = writeCount.incrementAndGet();
                store.transactionCommitted( count, count, count );
            } ) );

            race.addContestants( 3, until( end, throwing( () -> {
                try ( PageCursor cursor = pf.io( 0, PagedFile.PF_SHARED_READ_LOCK ) )
                {
                    assertTrue( cursor.next() );
                    long logVersion, byteOffset;
                    do
                    {
                        logVersion = store.getRecordValue( cursor,
                                MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION );
                        byteOffset = store.getRecordValue( cursor,
                                MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET );
                    }
                    while ( cursor.shouldRetry() );
                    assertLogVersionEqualsByteOffset( logVersion, byteOffset, "file" );
                    fileReadCount.incrementAndGet();
                }
            } ) ) );

            race.addContestants( 3, until( end, () -> {
                long[] transaction = store.getLastClosedTransaction();
                assertLogVersionEqualsByteOffset( transaction[0], transaction[1], "API" );
                apiReadCount.incrementAndGet();
            } ) );
            race.go();
        }
    }

After Change


            race.withEndCondition( () -> writeCount.get() >= lowerLimit &&
                    fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit &&
                    currentTimeMillis() >= endTime );
            race.addContestants( 3, () -> {
                long count = writeCount.incrementAndGet();
                store.transactionCommitted( count, count, count );
            } );

            race.addContestants( 3, throwing( () -> {
                try ( PageCursor cursor = pf.io( 0, PagedFile.PF_SHARED_READ_LOCK ) )
                {
                    assertTrue( cursor.next() );
                    long logVersion, byteOffset;
                    do
                    {
                        logVersion = store.getRecordValue( cursor,
                                MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION );
                        byteOffset = store.getRecordValue( cursor,
                                MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET );
                    }
                    while ( cursor.shouldRetry() );
                    assertLogVersionEqualsByteOffset( logVersion, byteOffset, "file" );
                    fileReadCount.incrementAndGet();
                }
            } ) );

            race.addContestants( 3, () -> {
                long[] transaction = store.getLastClosedTransaction();
                assertLogVersionEqualsByteOffset( transaction[0], transaction[1], "API" );
                apiReadCount.incrementAndGet();
            } );
            race.go();
        }
    }